/*
 * Project: Sudoku Explainer
 * Copyright (C) 2006-2007 Nicolas Juillerat
 * 
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.checks;

import com.onegravity.sudoku.solver.HintResource;
import com.onegravity.sudoku.solver.accumulator.HintsAccumulator;
import com.onegravity.sudoku.solver.accumulator.StopHintProductionException;
import com.onegravity.sudoku.solver.core.FinalHintProducer;
import com.onegravity.sudoku.solver.core.WarningHintProducer;
import com.onegravity.sudoku.solver.data.Grid;

/**
 * Check for invalid sudoku based on the number of clues.
 * If less than 17 clues are given, an appropriate warning hint is produced.
 */
public class TooFewGivensProducer implements WarningHintProducer, FinalHintProducer {

	public void getHints(Grid grid, HintsAccumulator accu) throws StopHintProductionException {
		int threshold = grid.isJigsaw() ? 14 :  grid.hasExtraRegions() ? 16 : 17;
        int countSolved = 0;
        for (int y = 0; y < 9; y++) {
            for (int x = 0; x < 9; x++) {
                if (!grid.getCell(x, y).isEmpty()) countSolved++;
            }
        }
        if (countSolved == 81) {
            WarningMessage message = new WarningMessage(grid, null, HintResource.SUDOKU_SOLVED);
            accu.add(message);
        }
        else if (countSolved < threshold) {
            WarningMessage message = new TooFewGivensWarning(grid, null, HintResource.TOO_FEW_GIVENS, threshold, countSolved);
            accu.add(message);
        }
    }

    @Override
	public String getProducerName() {
		return null;
	}
}